<?php
namespace Kxdr\Model;
use Think\Model\ViewModel;
class EventViewModel extends ViewModel {
   public $sid;
   public $id;
   public $fields = "id,title,pic_url,gifting_time,game_name,game_descrip,description,start_time,time_out,time_out_type";
   public $viewFields = array(
     'event'=>array('_table'=>"sm_kxdr_events",'id','game_id','think_type','think_type_way','time_out','time_out_type','title','description','pic_url','logo_url','need_seeds','gifting_time','assign_id','h5url','multi_no','multi_yes','status','_type'=>'LEFT'),
	 'game'=>array('_table'=>'sm_kxdr_games','name'=>'game_name','start_time','location','description'=>'game_descrip','pic_url'=>'game_pic_url','status'=>'game_status','status_end_time','_on'=>'event.game_id=game.id','_type'=>'LEFT'),
	 );
   public function getEventView(){
	   	$event = current($this->where("`event`.`sid`=".$this->sid." AND `event`.`id`=".$this->id)->getField($this->fields));
		if($event["time_out_type"]==1){
			$event["end_guess_time"] = strtotime($event["start_time"])+$event["time_out"];
		}else{
			$event["end_guess_time"] = strtotime($event["start_time"])-$event["time_out"];
		}
		$event["is_vaild"] = $event["end_guess_time"] - time();
		$event["end_guess_time"] = date("Y-m-d H:i:s",$event["end_guess_time"]);
		$event["game_time_str"] = GetTimeInfo(strtotime($event["start_time"]));
		$event["guess_time_str"] = GetTimeInfo(strtotime($event["end_guess_time"]));
		$event["left_time_str"] = LeftTime(strtotime($event["end_guess_time"]));
		return $event;
   }
 }
 